﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace FierceWar
{
	public class AboutScreen : MenuScreen
	{
		private MenuEntriesManager _menuEntriesManager;
		private MenuEntry _back;

		private TypingMessage _messageTitle;
		private TypingMessage _messageBody;

		private Rectangle _outerRectangle;
		private Rectangle _innerRectangle;

		public AboutScreen(GameResources resources, EventHandler screenEvent)
			: base(resources, screenEvent)
		{
			_back = new MenuEntry(resources, "Back", 800.0f, 100.0f);
			_menuEntriesManager = new MenuEntriesManager(resources,
				new List<EventHandler>() { screenEvent });
			_menuEntriesManager.MenuEntries.Add(_back);
			_menuEntriesManager.OriginY = 500;
			_menuEntriesManager.DistanceInterval = 50;
			_menuEntriesManager.InitializePositions();

			StringBuilder sb = new StringBuilder();
			sb.AppendLine("Fierce War");
			sb.AppendLine("Survive if You Can");
			_messageTitle = new TypingMessage(resources, resources.AboutTitleFont,
				sb.ToString(), Color.White * 0.7f);
			_messageTitle.TimeToNextLetter = 100.0f;
			_messageTitle.OriginY = -80.0f;

			sb.Clear();
			sb.AppendLine("Version: 1.0");
			sb.AppendLine("Release date: 09-11-2011");
			sb.AppendLine("Authors:");
			sb.AppendLine("    Toan T. Nguyen");
			sb.AppendLine("    Vuong B. Tru");
			_messageBody = new TypingMessage(resources, resources.AboutBodyFont,
				sb.ToString(), Color.White);
			_messageBody.TimeToNextLetter = 50.0f;
			_messageBody.OriginY = 70.0f;

			_outerRectangle = new Rectangle(
					(Resources.GraphicsDevice.Viewport.Width - 500) / 2,
					(Resources.GraphicsDevice.Viewport.Height - 450) / 2 + 50,
					500, 450);
			_innerRectangle = new Rectangle(
					(Resources.GraphicsDevice.Viewport.Width - 480) / 2,
					(Resources.GraphicsDevice.Viewport.Height - 430) / 2 + 50,
					480, 430);
		}

		public override void Update(Microsoft.Xna.Framework.GameTime gameTime)
		{
			_messageTitle.Update(gameTime);
			_messageBody.Update(gameTime);
			_menuEntriesManager.Update(gameTime);
			base.Update(gameTime);
		}

		public override void Draw(Microsoft.Xna.Framework.GameTime gameTime)
		{
			// Draw background.
			Resources.SpriteBatch.Draw(Resources.BackgroundTexture,
				FullScreen, Color.White);
			// Draw outer rectangle.
			Resources.SpriteBatch.Draw(Resources.BlankTexture,
				_outerRectangle,
				Color.Black * 0.35f);
			// Draw inner rectangle.
			Resources.SpriteBatch.Draw(Resources.BlankTexture,
				_innerRectangle,
				Color.Black * 0.35f);
			// Draw text.
			_messageTitle.Draw();
			_messageBody.Draw();
			// Draw menu entry.
			_menuEntriesManager.Draw();
			base.Draw(gameTime);
		}

		public override void Reset()
		{
			base.Reset();

			_messageTitle.Reset();
			_messageBody.Reset();
		}
	}
}
